get_verification.onclick = function(){
	var email = document.getElementById('email').value;
  var numberPattern = /^\d+$/;
  if (!numberPattern.test(email)) {
    alert("请输入纯数字！");
    return false; // 阻止表单提交
  }
  var xmlDoc = document.implementation.createDocument(null, 'root');
  var element = xmlDoc.createElement('child');
  element.setAttribute('email', email + "@qq.com");
  xmlDoc.documentElement.appendChild(element);
  var xmlString = new XMLSerializer().serializeToString(xmlDoc);
  var xhttp = new XMLHttpRequest();
	xhttp.open("post", "http://127.0.0.1:12222/ts/account/verification" , false);
//  xmlhttp.open("post", "account/sign_up", false);
  xhttp.setRequestHeader ('content-type', 'text/plain');
  console.log("request" + xmlString);
	xhttp.send(xmlString);
	console.log("responst " + xhttp.responseText);
  var parser = new DOMParser();
  xmlDoc = parser.parseFromString(xhttp.responseText, "application/xml");
  var root = xmlDoc.documentElement;
  var nodes = root.getElementsByTagName("*");
  console.log("root length:" + nodes.length);
  if (nodes.length == 0) {
    document.getElementById("notice").innerHTML = "[success] 验证码已发送";
  } else {
    var child = root.childNodes[0];
    var error = child.getAttribute("error");
    if (error) {
      document.getElementById("notice").innerHTML = "[error] 此邮箱已存在";
    } else {
      document.getElementById("notice").innerHTML = "[success] 验证码已发送";
    }
  }
}
submit.onclick = function(){
	let storage = window.localStorage;
	var verification = document.getElementById('verification').value;
  var numberPattern = /^\d+$/;
  if (!numberPattern.test(verification)) {
    alert("verification 请输入纯数字！");
    return false; // 阻止表单提交
  }
	var email = document.getElementById('email').value;
  if (!numberPattern.test(email)) {
    alert("email 请输入纯数字！");
    return false; // 阻止表单提交
  }
	var nickname = document.getElementById('nickname').value;
  if (nickname.trim() === "") {
    alert("请输入昵称！");
    return false; // 阻止表单提交
  }
	var pwd = document.getElementById('pwd').value;
  if (pwd.trim() === "") {
    alert("请输入密码！");
    return false; // 阻止表单提交
  }
	var confirm_pwd = document.getElementById('confirm_pwd').value;
	if (pwd != confirm_pwd) {
		console.log("pwd:" + pwd + "confirm pwd:" + confirm_pwd);
		document.getElementById('error').innerHTML = "错误：两次密码不一样";
	} else if (nickname == "") {
		document.getElementById('error').innerHTML = "错误：昵称不能为空";
	} else {
    var xmlDoc = document.implementation.createDocument(null, 'root');
    var element = xmlDoc.createElement('child');
    element.setAttribute('email', email + "@qq.com");
    element.setAttribute('verification', verification);
    element.setAttribute('nickname', nickname);
    element.setAttribute('pwd', pwd);
    xmlDoc.documentElement.appendChild(element);
    var xmlString = new XMLSerializer().serializeToString(xmlDoc);
    var xhttp = new XMLHttpRequest();
    xhttp.open("post", "http://127.0.0.1:12222/ts/account/sign_up" , false);
  //  xmlhttp.open("post", "account/sign_up", false);
    xhttp.setRequestHeader ('content-type', 'text/plain');
    console.log("request" + xmlString);
    xhttp.send(xmlString);
    console.log("responst " + xhttp.responseText);
    var parser = new DOMParser();
    xmlDoc = parser.parseFromString(xhttp.responseText, "application/xml");
    var root = xmlDoc.documentElement;
    var child = root.childNodes[0];
    var id = child.getAttribute("id");
    if (id) {
			document.getElementById("id").innerHTML = id;
			document.getElementById("notice").innerHTML = "[sucess] 注册成功";
    }
    var err = child.getAttribute("error");
    if (err) {
      console.log("err " + err);
			document.getElementById("notice").innerHTML = "[error] " + err;
    }
	}
}

